import { createFileRoute } from '@tanstack/react-router'
import Tables from '@/features/tables'
import { tableKeys, tables } from '@/api/tables'
import { Table } from '@/features/tables/data/schema'

export const Route = createFileRoute('/_authenticated/tables/')({
  component: Tables,
  loader: async ({ context: { queryClient } }): Promise<{ tableList: Table[] }> => {
    const res = await queryClient.fetchQuery({
      queryKey: tableKeys.all(),
      queryFn: tables,
    })
    return { tableList: res.data.data }
  },
})
